//
// Created by zhou on 2021/10/30.
//
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int count(int x){
        if(x<3)return 0;
        else return (x-2)*(x-1)/2;
    }
    int numberOfArithmeticSlices(vector<int>& nums) {
        int size=nums.size();
        if(size<3)return 0;
        vector<int> dp(size);
        int res=0;
        int m=-1;
        int cur=INT_MAX;
        for(int i=1;i<size;i++){
            if(nums[i]-nums[i-1]!=cur){
                m++;
                dp[m]=2;
                cur=nums[i]-nums[i-1];
            }
            else{
                dp[m]++;
            }
        }
        for(auto x:dp){
            res+= count(x);
        }
        return res;
    }
};
int main(){
    vector<int > nums={1,2,3,4,5,-1,-7};
    Solution solution;
    cout<<solution.numberOfArithmeticSlices(nums);
}